// Include files.
#include "SystematicRobot.hpp"
#include "CompoundController.hpp"

using namespace std;

/**
 *  Constructor for CompoundController.
 */
CompoundController::CompoundController() :
	m_robot(NULL)
{
}

/**
 *  Destructor for CompoundController.
 */
CompoundController::~CompoundController()
{
}

/**
 *  Adds a controller to the list of controllers to be activated/deactivated when the CompoundController gets activated/deactivated (respectivly).
 *  
 *  @param controller The controller to be activated/deactivated when the CompoundController gets activated/deactivated (respectivly).
 */
void CompoundController::AddController(RobotController &controller)
{
	m_controllers.push_back(&controller);
	
	if (m_robot != NULL)
		m_robot->AddController(controller);
}

void CompoundController::ActivateImpl()
{
	vector<RobotController*>::iterator it;
	
	for (it = m_controllers.begin(); it != m_controllers.end(); ++it)
		(*it)->Activate();
}

void CompoundController::DeactivateImpl()
{
	vector<RobotController*>::iterator it;
	
	for (it = m_controllers.begin(); it != m_controllers.end(); ++it)
		(*it)->Deactivate();
}

void CompoundController::HandleAddedToRobot(SystematicRobot &robot)
{
	m_robot = &robot;
	
	vector<RobotController*>::iterator it;
	
	for (it = m_controllers.begin(); it != m_controllers.end(); ++it)
		m_robot->AddController(*(*it));
}
